import 'dart:ui';

import 'package:flutter/material.dart';
import 'package:flutter_swiper/flutter_swiper.dart';
import 'package:magic_car/util/HttpHelper.dart';
import 'package:magic_car/util/colors.dart';
import 'package:magic_car/util/config.dart';
import 'package:magic_car/util/galleryphotoview.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:toast/toast.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:flutter/services.dart';
import 'package:fluwx/fluwx.dart';
import 'package:cached_network_image/cached_network_image.dart';

class CardetailPage extends StatefulWidget {
  // CardetailPage({Key key, this.title}) : super(key: key);

  //final String title;
  final Map param;
  final int is_my_car ;
  CardetailPage(this.param,this.is_my_car);

  @override
  _MyHomePageState createState() => new _MyHomePageState(this.param);
}

class _MyHomePageState extends State<CardetailPage> {
  WeChatScene scene = WeChatScene.SESSION;
  List view_arr = new List();
  final Map param;
  _MyHomePageState(this.param);
  Map order_info;
  List formList;

  initState() {
    order_info = param;
    view_arr = [
      {
        'title': '微信好友',
        'icon': 'resource/images/user/wechat.jpeg',
        'tag': WeChatScene.SESSION
      },
      {
        'title': '朋友圈',
        'icon': 'resource/images/user/wechat1.jpeg',
        'tag': WeChatScene.TIMELINE
      }
    ];
    super.initState();
    formList = [
      {
        "title": '车牌号111111',
        'sub_title': '云A00001',
        'sub_color': Color.fromRGBO(27, 182, 251, 1)
      },
      {
        "title": '车牌号',
        'sub_title': '云A00001',
        'sub_color': Color.fromRGBO(27, 182, 251, 1)
      },
      {
        "title": '车牌号',
        'sub_title': '云A00001',
        'sub_color': Color.fromRGBO(27, 182, 251, 1)
      },
      {
        "title": '车牌号',
        'sub_title': '云A00001',
        'sub_color': Color.fromRGBO(27, 182, 251, 1)
      },
    ];
  }

  submitorder()async{
    
    Map<String, String> map = new Map();
    SharedPreferences pref = await SharedPreferences.getInstance();
    map["uid"] = pref.getString('uid');
   map["oid"] = order_info["id"].toString();

    print(map);

    HttpHelper.post(HttpHelper.API_Create_auth_by_car, (data) async {
      if (data != null) {
        Toast.show(data["msg"], context, duration: 2);
        if(data["code"]==1){
          Navigator.pop(context);
        }
      }
    }, params: map);
  }

  Widget buildcontent() {
    List<Widget> tiles = [];
    Widget content;
    tiles.add(flash());
    // for (var item in formList) {
    //   tiles.add(new Row(children: <Widget>[
    //     Expanded(child:
    //     new Padding(
    //         padding: new EdgeInsets.fromLTRB(10, 10, 10, 0),
    //         child: new Text(
    //           item['title'],
    //           style: TextStyle(fontSize: 16),
    //         )),flex: 2,),
    //          new Padding(
    //         padding: new EdgeInsets.fromLTRB(10, 10, 10, 0),
    //         child: new Text(
    //           item['sub_title'],
    //           style: TextStyle(fontSize: 16,color: item['sub_color']),
    //         )),
    //   ],));
    // }
    content = new Column(
        children: tiles //重点在这里，因为用编辑器写Column生成的children后面会跟一个<Widget>[]，
        //此时如果我们直接把生成的tiles放在<Widget>[]中是会报一个类型不匹配的错误，把<Widget>[]删了就可以了
        );
    return content;
  }

  //滚动图片
  Widget flash() {
    var content = Container(
        width: MediaQuery.of(context).size.width,
        height: 250.0,
        child: Swiper(
          itemBuilder: _swiperBuilder,
          itemCount: param["car_thumb"].length,
          pagination: new SwiperPagination(
              builder: DotSwiperPaginationBuilder(
            color: Colors.black54,
            activeColor: Colors.white,
          )),
          // control: new SwiperControl(),
          scrollDirection: Axis.horizontal,
          autoplay: true,
          onTap: (index) {
            Navigator.of(context).push(new FadeRoute(
                page: GalleryPhotoViewWrapper(
              galleryItems: imageModel(param["car_thumb"]),
              backgroundDecoration: const BoxDecoration(
                color: Colors.black,
              ),
              initialIndex: index,
            )));
            // Navigator.of(context).push(
            //   NinePicture(param["car_thumb"], index),
            // );
          },
        ));

    return content;
  }

  Widget _swiperBuilder(BuildContext context, int index) {
    return (Image.network(param["car_thumb"][index], fit: BoxFit.contain
        // fit: BoxFit.contain,
        ));
  }

  //
  Widget price() {
    Widget content = Padding(
        padding: new EdgeInsets.fromLTRB(0, 5, 0, 0),
        child: Container(
          child: Text(
            '¥' + param["car_price"] + '万',
            style:
                TextStyle(color: Color.fromRGBO(225, 102, 82, 1), fontSize: 20,fontWeight: FontWeight.bold),
          ),
        ));
    return content;
  }

  //标题
  Widget titles() {
    Widget content = Padding(
        padding: new EdgeInsets.fromLTRB(0, 10, 0, 5),
        child: Container(
          child: Text(
            param["title"],
            style:
                TextStyle(color: Color.fromRGBO(16, 29, 55, 1), fontSize: 16,fontWeight: FontWeight.w400),
          ),
        ));
    return content;
  }

  //发布者
  Widget distube() {
    Widget content = Padding(
        padding: new EdgeInsets.fromLTRB(0, 20, 0, 5),
        child: new Column(
          children: <Widget>[
            Row(
              children: <Widget>[
                new Container(
                    alignment: Alignment.topLeft,
                    width: 20,
                    child:
                        new Image.asset('resource/images/zhanshi/dizhi.png')),

                new Padding(
                  padding: new EdgeInsets.fromLTRB(5, 0, 0, 0),
                  child: Text('发布者'),
                )
                // Expanded(
                //     flex: 1,
                //     child:
                //         new Image.asset('resource/images/zhanshi/dizhi.png')),
                // Expanded(
                //     flex: 9,
                //     child: new Padding(
                //       padding: new EdgeInsets.fromLTRB(30, 0, 0, 0),
                //       child: Text('发布者'),
                //     ))
              ],
            ),
            // Padding(
            //     padding: new EdgeInsets.fromLTRB(0, 15, 0, 15),
            //     child: Row(
            //       children: <Widget>[
            //         new Container(
            //             alignment: Alignment.topLeft,
            //             width: 20,
            //             child: new Text('')),
            //         new Padding(
            //           padding: new EdgeInsets.fromLTRB(5, 0, 0, 0),
            //           child: Text("暂无",
            //               style: new TextStyle(
            //                   color: Color.fromRGBO(120, 120, 120, 1),
            //                   fontSize: 13)),
            //         )
            //       ],
            //     )),
            Row(
              children: <Widget>[
                new Container(
                    alignment: Alignment.topLeft,
                    width: 20,
                    child: new Text('')),

                new Padding(
                  padding: new EdgeInsets.fromLTRB(5, 5, 0, 0),
                  child: Text(
                      param["contact_people"] + ' / ' + param["contact_mobile"],
                      style: new TextStyle(
                          color: Color.fromRGBO(120, 120, 120, 1),
                          fontSize: 13)),
                )
                // Expanded(
                //     flex: 1,
                //     child:
                //         new Image.asset('resource/images/zhanshi/dizhi.png')),
                // Expanded(
                //     flex: 9,
                //     child: new Padding(
                //       padding: new EdgeInsets.fromLTRB(30, 0, 0, 0),
                //       child: Text('发布者'),
                //     ))
              ],
            ),
          ],
        ));
    return content;
  }

  //上架时间
  Widget distubetime() {
    Widget content = Padding(
        padding: new EdgeInsets.fromLTRB(0, 15, 0, 5),
        child: new Column(
          children: <Widget>[
            Row(
              children: <Widget>[
                //     new Image.asset('resource/images/zhanshi/dizhi.png'),

                // new Padding(
                //   padding: new EdgeInsets.fromLTRB(25, 0, 0, 0),
                //   child: Text('发布者'),
                // )
                new Container(
                    alignment: Alignment.topLeft,
                    width: 20,
                    child: new Image.asset(
                        'resource/images/zhanshi/shangjia.png')),
                new Padding(
                  padding: new EdgeInsets.fromLTRB(5, 0, 0, 0),
                  child: RichText(
                    text: TextSpan(
                        text: '上架时间：',
                        style: TextStyle(fontSize: 14, color: Colors.black),
                        children: [
                          TextSpan(
                              text: param["add_time"],
                              style: TextStyle(
                                  fontSize: 13,
                                  color: Color.fromRGBO(120, 120, 120, 1)))
                        ]),
                  ),
                  //child: Text('上架时间：' + param["add_time"]),
                )
              ],
            ),
          ],
        ));
    return content;
  }

  Widget order_sn() {
    return Padding(
      padding: new EdgeInsets.fromLTRB(0, 10, 0, 0),
      child: new Row(
        crossAxisAlignment: CrossAxisAlignment.start,
        mainAxisAlignment: MainAxisAlignment.start,
        children: <Widget>[
          GestureDetector(
              onLongPress: () {
                Clipboard.setData(ClipboardData(text: param['car_sn']));
                Toast.show('编号已复制', context);
              },
              child: new Text(
                '车源编号：' + param['car_sn'],
                style: TextStyle(
                    color: Color.fromRGBO(100, 100, 100, 1), fontSize: 12),
              ))
          // int.parse(param["status"]) > 1
          //     ? new Text('车况检测报告不会直接展示，请联系车主获取。',style: TextStyle(color:Colors.red,fontSize: 12),)
          //     : new Container(height: 0),
        ],
      ),
    );
  }

  Widget inspecttip() {
    return Padding(
      padding: new EdgeInsets.fromLTRB(0, 15, 0, 0),
      child: new Row(
        crossAxisAlignment: CrossAxisAlignment.start,
        mainAxisAlignment: MainAxisAlignment.start,
        children: <Widget>[
          int.parse(param["status"]) > 1
              ? new Text(
                  '车况检测报告不会直接展示，请联系车主获取。',
                  style: TextStyle(color: Colors.red, fontSize: 12),
                )
              : new Container(height: 0),
        ],
      ),
    );
  }

  Widget inspect() {
    return Padding(
      padding: new EdgeInsets.fromLTRB(0, 15, 0, 0),
      child: new Row(
        crossAxisAlignment: CrossAxisAlignment.start,
        mainAxisAlignment: MainAxisAlignment.start,
        children: <Widget>[
          int.parse(param["status"]) > 1
              ? new GestureDetector(
                  onTap: () {
                    //检测结果
                  },
                  child: Image.asset('resource/images/baoxiu/inspected.png',
                      width: 15, height: 17))
              : new Container(height: 0),
          int.parse(param["status"]) > 1
              ? new GestureDetector(
                  onTap: () {
                    //检测结果
                  },
                  child: Padding(
                      padding: new EdgeInsets.fromLTRB(5, 0, 0, 0),
                      child: Text('检测报告',
                          style: TextStyle(
                            fontSize: 11,
                            color: Color.fromRGBO(212, 35, 122, 1),
                          ))))
              : Container(height: 0),
          param["is_guratee"].toString() == "1"
              ? new GestureDetector(
                  onTap: () {
                    //查看保修
                  },
                  child: Padding(
                      padding: new EdgeInsets.fromLTRB(15, 0, 0, 0),
                      child: Image.asset('resource/images/baoxiu/guarateed.png',
                          width: 15, height: 17)))
              : Container(height: 0),
          param["is_guratee"].toString() == "1"
              ? new GestureDetector(
                  onTap: () {
                    //查看保修
                  },
                  child: Padding(
                      padding: new EdgeInsets.fromLTRB(5, 0, 0, 0),
                      child: Text('保修证明',
                          style: TextStyle(
                            fontSize: 11,
                            color: Color.fromRGBO(18, 150, 219, 1),
                          ))))
              : Container(height: 0)
        ],
      ),
    );
  }

  //
  Widget car_base_info() {
    Widget content = Padding(
        padding: new EdgeInsets.fromLTRB(0, 15, 0, 5),
        child: new Column(
          mainAxisAlignment: MainAxisAlignment.start,
          crossAxisAlignment: CrossAxisAlignment.start,
          children: <Widget>[
            Row(
              children: <Widget>[
                // new Container(
                //     alignment: Alignment.topLeft,
                //     width: 20,
                //     child: new Image.asset(
                //         'resource/images/zhanshi/cheliangguanli.png')),
                new Padding(
                    padding: new EdgeInsets.fromLTRB(5, 0, 0, 0),
                    child: Text('基础信息'))
              ],
            ),
          ],
        ));
    return content;
  }

  Widget heardwidget(title) {
    Widget content = Padding(
        padding: new EdgeInsets.fromLTRB(0, 15, 0, 5),
        child: new Column(
          mainAxisAlignment: MainAxisAlignment.start,
          crossAxisAlignment: CrossAxisAlignment.start,
          children: <Widget>[
            Row(
              children: <Widget>[
                // new Container(
                //     alignment: Alignment.topLeft,
                //     width: 20,
                //     child: new Image.asset(
                //         'resource/images/zhanshi/cheliangguanli.png')),
                new Padding(
                    padding: new EdgeInsets.fromLTRB(5, 0, 0, 0),
                    child: Text(title,
                        style: TextStyle(
                            color: Colors.black,
                            fontSize: 16,
                            fontWeight: FontWeight.w600))),
              ],
            ),
          ],
        ));
    return content;
  }

  String formatNum(double num, int postion) {
    if ((num.toString().length - num.toString().lastIndexOf(".") - 1) <
        postion) {
      //小数点后有几位小数
      return num.toStringAsFixed(postion)
          .substring(0, num.toString().lastIndexOf(".") + postion + 1)
          .toString();
    } else {
      return num.toString()
          .substring(0, num.toString().lastIndexOf(".") + postion + 1)
          .toString();
    }
  }

  Widget car_base_info_detail() {
    List<Widget> tiles = [];
    // List carinfo =
    //     param["inspectorItemsResult"]["otherData"]["checkData"][0]["post"];

    // var km = param['bxlc'].toString(); //l里程
    // var pl=param['bxlc']; //排量
    // var qd=param['bxlc']; //驱动
    // var fdj=param['bxlc']; //发动鸡
    // var cj=param['bxlc']; //车架号
    // var pf=param['bxlc']; //排放标准
    // var lx=param['bxlc']; //类型
    // var gc=param['bxlc']; //国产、进口
    // var cp=param['bxlc']; //车牌
    // for (var item in carinfo) {
    //   if (item['id'] == "3034") {
    //     lx = item['value'];
    //   }
    //   if (item['id'] == "4035") {
    //     qd = item['value'];
    //   }

    //   if (item['id'] == "4034") {
    //     gc = item['value'];
    //   }

    //   if (item['id'] == "4033") {
    //     pf = item['value'];
    //   }

    //   if (item['id'] == "4032") {
    //     fdj = item['value'];
    //   }
    //   if (item['id'] == "4031") {
    //     pl = item['value'];
    //   }

    //   if (item['id'] == "4030") {
    //     double temp = double.parse(item['value']) / 10000;
    //     km = formatNum(temp, 2) + '万';
    //   }

    //   if (item['id'] == "3030") {
    //     cj = item['value'];
    //   }

    //   if (item['id'] == "3029") {
    //     cp = item['value'];
    //   }
    // }

    Color baseColor = Color.fromRGBO(150, 150, 150, 1);
    //var item = carinfo[i];
    tiles.add(Padding(
        padding: new EdgeInsets.fromLTRB(0, 5, 30, 0),
        child: new Column(children: <Widget>[
          Row(children: <Widget>[
            Expanded(
              child: Container(
                  child: Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      mainAxisAlignment: MainAxisAlignment.start,
                      children: <Widget>[
                    Text(
                      param['sp_time'] == null ? '暂无' : param['sp_time'],
                      style:
                          TextStyle(fontSize: 18, fontWeight: FontWeight.w400),
                    ),
                    Padding(
                      padding: new EdgeInsets.fromLTRB(0, 5, 0, 0),
                      child: Text('上牌时间', style: TextStyle(color: baseColor)),
                    )
                  ])),
              flex: 1,
            ),
            Expanded(
              child: Container(
                  child: Column(
                      crossAxisAlignment: CrossAxisAlignment.center,
                      mainAxisAlignment: MainAxisAlignment.center,
                      children: <Widget>[
                    Text(
                      param['bxlc'] == null ? '暂无' : param['bxlc'],
                      style:
                          TextStyle(fontSize: 18, fontWeight: FontWeight.w400),
                    ),
                    Padding(
                      padding: new EdgeInsets.fromLTRB(0, 5, 0, 0),
                      child: Text('表显里程', style: TextStyle(color: baseColor)),
                    )
                  ])),
              flex: 1,
            ),
            Expanded(
              child: Container(
                  child: Column(
                      crossAxisAlignment: CrossAxisAlignment.center,
                      mainAxisAlignment: MainAxisAlignment.center,
                      children: <Widget>[
                    Text(
                      param['pfbz'] == null ? '暂无' : param['pfbz'],
                      style:
                          TextStyle(fontSize: 18, fontWeight: FontWeight.w400),
                    ),
                    Padding(
                      padding: new EdgeInsets.fromLTRB(0, 5, 0, 0),
                      child: Text('排放标准', style: TextStyle(color: baseColor)),
                    )
                  ])),
              flex: 1,
            )
          ]),
          Padding(
              padding: new EdgeInsets.fromLTRB(0, 15, 0, 5),
              child: Row(children: <Widget>[
                Expanded(
                  child: Container(
                      child: Column(
                          crossAxisAlignment: CrossAxisAlignment.start,
                          mainAxisAlignment: MainAxisAlignment.start,
                          children: <Widget>[
                        Text(
                          param['pl'] == null ? '暂无' : param['pl'],
                          style: TextStyle(
                              fontSize: 18, fontWeight: FontWeight.w400),
                        ),
                        Padding(
                          padding: new EdgeInsets.fromLTRB(0, 5, 0, 0),
                          child: Text('排量', style: TextStyle(color: baseColor)),
                        )
                      ])),
                  flex: 1,
                ),
                Expanded(
                  child: Container(
                      child: Column(
                          crossAxisAlignment: CrossAxisAlignment.center,
                          mainAxisAlignment: MainAxisAlignment.center,
                          children: <Widget>[
                        Text(
                          param['bsx'] == null ? '暂无' : param['bsx'],
                          style: TextStyle(
                              fontSize: 18, fontWeight: FontWeight.w400),
                        ),
                        Padding(
                          padding: new EdgeInsets.fromLTRB(0, 5, 0, 0),
                          child:
                              Text('变速箱', style: TextStyle(color: baseColor)),
                        )
                      ])),
                  flex: 1,
                ),
                Expanded(
                  child: Container(
                      child: Column(
                          crossAxisAlignment: CrossAxisAlignment.center,
                          mainAxisAlignment: MainAxisAlignment.center,
                          children: <Widget>[
                        Text(
                          param['ghcs'] == null ? '暂无' : param['ghcs'],
                          style: TextStyle(
                              fontSize: 18, fontWeight: FontWeight.w400),
                        ),
                        Padding(
                          padding: new EdgeInsets.fromLTRB(0, 5, 0, 0),
                          child:
                              Text('过户次数', style: TextStyle(color: baseColor)),
                        )
                      ])),
                  flex: 1,
                )
              ])),
          Padding(
              padding: new EdgeInsets.fromLTRB(0, 15, 0, 5),
              child: Row(children: <Widget>[
                Expanded(
                  child: Container(
                      child: Column(
                          crossAxisAlignment: CrossAxisAlignment.start,
                          mainAxisAlignment: MainAxisAlignment.start,
                          children: <Widget>[
                        Text(
                          param['pzd'] == null ? '暂无' : param['pzd'],
                          style: TextStyle(
                              fontSize: 18, fontWeight: FontWeight.w400),
                        ),
                        Padding(
                          padding: new EdgeInsets.fromLTRB(0, 5, 0, 0),
                          child:
                              Text('所在城市', style: TextStyle(color: baseColor)),
                        )
                      ])),
                  flex: 1,
                ),
                // Expanded(
                //   child: Container(
                //       child: Column(
                //           crossAxisAlignment: CrossAxisAlignment.center,
                //           mainAxisAlignment: MainAxisAlignment.center,
                //           children: <Widget>[
                //         Text(
                //           fdj,
                //           style: TextStyle(fontSize: 18),
                //         ),
                //         Padding(
                //           padding: new EdgeInsets.fromLTRB(0, 5, 0, 0),
                //           child:
                //               Text('发动机号', style: TextStyle(color: baseColor)),
                //         )
                //       ])),
                //   flex: 1,
                // ),
                // Expanded(
                //   child: Container(
                //       child: Column(
                //           crossAxisAlignment: CrossAxisAlignment.center,
                //           mainAxisAlignment: MainAxisAlignment.center,
                //           children: <Widget>[
                //         Text(
                //           cp,
                //           style: TextStyle(fontSize: 14),
                //         ),
                //         Padding(
                //           padding: new EdgeInsets.fromLTRB(0, 5, 0, 0),
                //           child:
                //               Text('车牌号', style: TextStyle(color: baseColor)),
                //         )
                //       ])),
                //   flex: 1,
                // )
              ])),
        ])));

    Widget content = Padding(
        padding: new EdgeInsets.fromLTRB(5, 5, 0, 25),
        child: new Column(
          mainAxisAlignment: MainAxisAlignment.start,
          crossAxisAlignment: CrossAxisAlignment.start,
          children: tiles,
        ));
    return content;
  }

  //车辆详情
  Widget detail() {
    Widget content = Padding(
        padding: new EdgeInsets.fromLTRB(0, 15, 0, 5),
        child: new Column(
          mainAxisAlignment: MainAxisAlignment.start,
          crossAxisAlignment: CrossAxisAlignment.start,
          children: <Widget>[
            Row(
              children: <Widget>[
                new Container(
                    alignment: Alignment.topLeft,
                    width: 20,
                    child: new Image.asset(
                        'resource/images/zhanshi/cheliangguanli.png')),
                new Padding(
                    padding: new EdgeInsets.fromLTRB(5, 0, 0, 0),
                    child: Text('车辆详情')
                    // Row(
                    //   children: <Widget>[
                    //     Expanded(
                    //       flex: 1,
                    //       child: Text('上架时间'),
                    //     ),
                    //     Expanded(
                    //       flex: 1,
                    //       child: Text('2019.12.12'),
                    //     )
                    //   ],
                    // ),
                    )
              ],
            ),
          ],
        ));
    return content;
  }

  Widget detailInfo() {
    List<Widget> tiles = [];
    print(param['car_thumb']);

    tiles.add(Padding(
        padding: new EdgeInsets.fromLTRB(0, 5, 0, 0),
        child: Text("车源描述" + "：" + param["car_descrble"],
            style: new TextStyle(
                color: Color.fromRGBO(120, 120, 120, 1), fontSize: 13))));
    // List carinfo =
    //     param["inspectorItemsResult"]["otherData"]["checkData"][0]["post"];
    for (int i = 0; i < param["car_thumb"].length; i++) {
      tiles.add(Padding(
          padding: new EdgeInsets.fromLTRB(0, 5, 0, 0),
          child: Container(
              child: GestureDetector(
            child: Image.network(param["car_thumb"][i], fit: BoxFit.fill),
            onTap: () {
              Navigator.of(context).push(new FadeRoute(
                  page: GalleryPhotoViewWrapper(
                galleryItems: imageModel(param["car_thumb"]),
                backgroundDecoration: const BoxDecoration(
                  color: Colors.black,
                ),
                initialIndex: i,
              )));
              // Navigator.of(context).push(
              //   NinePicture(param["car_thumb"], i),
              // );
            },
          ))
          // child: param["car_thumb"][i] != null
          //     ? GestureDetector(
          //         child: Image.network(param["car_thumb"][i], fit: BoxFit.fill),
          //         onTap: () {
          //           NinePicture(param["car_thumb"], i);
          //         },
          //       )
          //     : new Container(height: 0),
          ));
    }
    // for (int i = 0; i < carinfo.length; i++) {
    //   var item = carinfo[i];
    //   tiles.add(Padding(
    //       padding: new EdgeInsets.fromLTRB(0, 5, 0, 0),
    //       child: Text(item["name"] + "：" + item["value"],
    //           style: new TextStyle(
    //               color: Color.fromRGBO(120, 120, 120, 1), fontSize: 13))));
    // }

    Widget content = Padding(
        padding: new EdgeInsets.fromLTRB(5, 5, 0, 25),
        child: new Column(
          mainAxisAlignment: MainAxisAlignment.start,
          crossAxisAlignment: CrossAxisAlignment.start,
          children: tiles,
        ));
    return content;
  }

//分享
  share() {
    String describle = "";

    // describle = order_info['brand_string']['name'] +
    //     '/' +
    //     order_info['cartype_string']['name'] +
    //     '/' +
    //     order_info['pl'] +
    //     '/' +
    //     order_info['pfbz'] +
    //     '/' +
    //     order_info['bxlc'];
    // var pics = order_info["inspectorItemsResult"]['pics']; //更改数据构造
    var zhengchezhaopian = order_info['car_thumb'][0];
    // for (var value in pics['post']) {
    //   if (value['name'] == '整车照片') {
    //     zhengchezhaopian = value['url'];
    //   }
    // }
    var model = WeChatShareWebPageModel(
      HttpHelper.host +
          '/app/index.php?i=16&j=16&c=entry&m=chemogu&do=mobile&r=car.carinfo' +
          '&id=' +
          param['id'],
      title: '车源信息',
      description: param['title'],
      //description: '233',
      thumbnail: zhengchezhaopian != ""
          ? WeChatImage.network(zhengchezhaopian)
          : WeChatImage.asset('resource/images/user/1024.png'),
      scene: scene,
    );
    shareToWeChat(model);
  }

  Widget _shareWidget() {
    return new Container(
      height: 160.0,
      child: new Column(
        children: <Widget>[
          new Padding(
            padding: EdgeInsets.fromLTRB(0.0, 10.0, 0.0, 0.0),
            child: new Container(
              height: 100.0,
              child: new GridView.builder(
                gridDelegate: new SliverGridDelegateWithFixedCrossAxisCount(
                    crossAxisCount: 2,
                    mainAxisSpacing: 1.0,
                    childAspectRatio: 1.0),
                itemBuilder: (BuildContext context, int index) {
                  var item = view_arr[index];
                  return new GestureDetector(
                      onTap: () {
                        //print(item['tag']);
                        Navigator.of(context).pop();
                        //选择检测师
                        setState(() {
                          scene = item['tag'];
                          share();
                        });
                      },
                      child: new Column(
                        crossAxisAlignment: CrossAxisAlignment.center,
                        mainAxisAlignment: MainAxisAlignment.center,
                        children: <Widget>[
                          new Padding(
                              padding: EdgeInsets.fromLTRB(0.0, 6.0, 0.0, 6.0),
                              child: new Container(
                                  decoration: new BoxDecoration(
                                    // 底色
                                    //        borderRadius: new BorderRadius.circular((20.0)), // 圆角度
                                    borderRadius: new BorderRadius.circular(
                                        25), // 也可控件一边圆角大小
                                  ),
                                  height: 50,
                                  width: 50,
                                  child: ClipRRect(
                                    borderRadius: BorderRadius.circular(25),
                                    child: FadeInImage.assetNetwork(
                                      placeholder: item['icon'],
                                      image: '',
                                      fit: BoxFit.cover,
                                    ),
                                  ))),
                          Expanded(child: new Text(item['title']))
                        ],
                      ));
                },
                itemCount: view_arr.length,
              ),
            ),
          ),
          new Container(
            height: 0.5,
            color: Colors.blueGrey,
          ),
          new Center(
            child: new Padding(
              padding: EdgeInsets.fromLTRB(0.0, 8.0, 0.0, 8.0),
              child: GestureDetector(
                  behavior: HitTestBehavior.opaque,
                  onTap: () {
                    Navigator.of(context).pop();
                    setState(() {});
                  },
                  child: new Text(
                    '取  消',
                    style:
                        new TextStyle(fontSize: 18.0, color: Colors.blueGrey),
                  )),
            ),
          ),
        ],
      ),
    );
  }

  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
        elevation: 0,
        titleSpacing: 0,
        title: new Text(
          '车辆信息',
          style: TextStyle(color: Colors.white,fontSize:Config.title_size),
        ),
        backgroundColor: Colours.app_main,
        leading: BackButton(color: Colors.white),
        actions: <Widget>[
          IconButton(
            icon: Icon(Icons.share),
            color: Colors.white,
            onPressed: () {
              if (order_info['car_status'].toString() != "2") {
                Toast.show('未上架车源不支持分享', context);
                return;
              }
              showModalBottomSheet(
                  context: context,
                  builder: (BuildContext context) {
                    return _shareWidget();
                  });
            },
          ),
        ],
      ),
      body: new Center(
          child: Padding(
              padding: new EdgeInsets.fromLTRB(20, 10, 20, 10),
              child: Stack(children: <Widget>[
               
                Align(
                  alignment: Alignment.bottomCenter,
                  child: new Padding(
                      padding: new EdgeInsets.fromLTRB(10, 0, 20, 0),
                      child: new Material(
                        color: Color.fromRGBO(239, 239, 239, 1),
                        //INK可以实现装饰容器
                        child: new Ink(
                          //用ink圆角矩形
                          //color: Color.fromRGBO(239, 239, 239, 1),
                          decoration: new BoxDecoration(
                            //背景

                            color: Colours.app_main,
                            //设置四周圆角 角度
                            borderRadius:
                                BorderRadius.all(Radius.circular(18.0)),
                            //设置四周边框
                            border: new Border.all(
                                width: 1,
                                color: Colours.app_main),
                          ),
                          child:
                          
                          widget.is_my_car==1?
                           order_info['appoint_order_id'].toString()=="0"?
                           new InkWell(

                              //圆角设置,给水波纹也设置同样的圆角
                              //如果这里不设置就会出现矩形的水波纹效果
                              borderRadius: new BorderRadius.circular(15.0),
                              //设置点击事件回调
                              onTap: () {
                                submitorder();
                                //submit();
                               // call();
                              },
                              child: Container(
                                //设置 child 居中
                                alignment: Alignment(0, 0),
                                height: 36,
                                //color: Color.fromRGBO(239, 239, 239, 1),
                                width: double.infinity,
                                child: Text(
                                  "认证检测",
                                  style: TextStyle(color: Colors.white),
                                ),
                              )):Container(height: 0,width: 0,):
                              new InkWell(

                              //圆角设置,给水波纹也设置同样的圆角
                              //如果这里不设置就会出现矩形的水波纹效果
                              borderRadius: new BorderRadius.circular(15.0),
                              //设置点击事件回调
                              onTap: () {
                                //submit();
                                call();
                              },
                              child: Container(
                                //设置 child 居中
                                alignment: Alignment(0, 0),
                                height: 36,
                                //color: Color.fromRGBO(239, 239, 239, 1),
                                width: double.infinity,
                                child: Text(
                                  "联    系",
                                  style: TextStyle(color: Colors.white),
                                ),
                              )),
                        ),
                      )),
                ),
                Align(
                    child: Padding(
                        padding: new EdgeInsets.fromLTRB(0, 0, 0, 50),
                        child: new ListView(
                          children: <Widget>[
                            flash(),
                            titles(),
                            price(),
                            order_sn(),
                            int.parse(param["status"]) > 1
                                ? inspect()
                                : Container(height: 0),
                            int.parse(param["status"]) > 1
                                ? inspecttip()
                                : Container(height: 0),
                            // distube(),
                            heardwidget("发布者"),
                            new Container(
                                child: new Padding(
                              padding: new EdgeInsets.fromLTRB(5, 5, 0, 0),
                              child: Text(
                                  param["contact_people"] +
                                      ' / ' +
                                      param["contact_mobile"],
                                  style: new TextStyle(
                                      color: Color.fromRGBO(120, 120, 120, 1),
                                      fontSize: 13)),
                            )),
                            heardwidget("上架时间"),
                            new Container(
                              //param["add_time"]
                              child: new Padding(
                                padding: new EdgeInsets.fromLTRB(5, 5, 0, 0),
                                child: Text(param["add_time"],
                                    style: new TextStyle(
                                        color: Color.fromRGBO(120, 120, 120, 1),
                                        fontSize: 13)),
                              ),
                            ),
                            // distubetime(),
                            // car_base_info(),
                            heardwidget("基础信息"),
                            car_base_info_detail(),
                            heardwidget("车辆详情"),
                            //detail(),
                            detailInfo(),
                          ],
                        ))),
              ]))),
    );
  }

  call() async {
    String url = 'tel:' + param["contact_mobile"];

    if (await canLaunch(url)) {
      await launch(url);
    } else {
      throw 'Could not launch $url';
    }
  }

  List imageModel(data) {
    List img_temp = [
      "https://car3.autoimg.cn/cardfs/product/g1/M09/3F/A8/240x180_0_q95_c42_autohomecar__ChwFqV69W4KAf_AzAAShphUBgV4514.jpg",
      "https://car2.autoimg.cn/cardfs/product/g25/M09/6E/D2/240x180_0_q95_c42_autohomecar__ChwFj169W32Ad5ehAAT2abQFAio994.jpg",
      "https://car2.autoimg.cn/cardfs/product/g25/M08/6E/D2/240x180_0_q95_c42_autohomecar__ChwFj169W3uATe71AASA9ZdptWg816.jpg",
      "https://car2.autoimg.cn/cardfs/product/g25/M0B/73/06/240x180_0_q95_c42_autohomecar__ChsEmF69W3qAYeneAAQeve0abAo167.jpg",
    ];
    List imgList = List();
    for (int x = 0; x < data.length; x++) {
      GalleryExampleItem item = GalleryExampleItem();
      item.id = '$x';
      item.resource = data[x];
      // item.resource = data[x]["url"];
      imgList.add(item);
    }
    print(imgList.first.id);

    return imgList;
  }
}

class NinePicture<T> extends PopupRoute<T> {
  final String barrierLabel;
  final List picList;
  final int index;
  int startX;
  int endX;

  NinePicture(this.picList, this.index, {this.barrierLabel});

  @override
  Duration get transitionDuration => Duration(milliseconds: 2000);

  @override
  @override
  Color get barrierColor => Colors.black54;

  @override
  bool get barrierDismissible => true;

  AnimationController _animationController;

  @override
  AnimationController createAnimationController() {
    assert(_animationController == null);
    _animationController =
        BottomSheet.createAnimationController(navigator.overlay);
    return _animationController;
  }

  @override
  Widget buildPage(BuildContext context, Animation<double> animation,
      Animation<double> secondaryAnimation) {
    return MediaQuery.removePadding(
      removeTop: true,
      context: context,
      child: GestureDetector(
        child: AnimatedBuilder(
          animation: animation,
          builder: (BuildContext context, Widget child) => GestureDetector(
            onTap: () {
              Navigator.pop(context);
            },
            child: _PictureWidget(picList, index),
          ),
        ),
      ),
    );
  }
}

class _PictureWidget extends StatefulWidget {
  final List picList;
  final int index;

  _PictureWidget(this.picList, this.index);

  @override
  State createState() {
    return _PictureWidgetState();
  }
}

class _PictureWidgetState extends State<_PictureWidget> {
  int startX = 0;
  int endX = 0;
  int index = 0;

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    index = widget.index;
  }

  @override
  Widget build(BuildContext context) {
    return new Material(
      color: Colors.transparent,
      child: new Container(
        width: double.infinity,
        child: Stack(
          children: <Widget>[
            GestureDetector(
              child: Center(
                child: CachedNetworkImage(
                  imageUrl: widget.picList[index],
                  fit: BoxFit.cover,
                ),
              ),
              onHorizontalDragDown: (detail) {
                startX = detail.globalPosition.dx.toInt();
              },
              onHorizontalDragUpdate: (detail) {
                endX = detail.globalPosition.dx.toInt();
              },
              onHorizontalDragEnd: (detail) {
                _getIndex(endX - startX);
                setState(() {});
              },
              onHorizontalDragCancel: () {},
            ),
            Align(
              alignment: Alignment.bottomCenter,
              child: Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: List.generate(
                  widget.picList.length,
                  (i) => GestureDetector(
                    child: Padding(
                        padding: new EdgeInsets.fromLTRB(2, 0, 2, 0),
                        child: CircleAvatar(
                          foregroundColor: Theme.of(context).primaryColor,
                          radius: 3.0,
                          backgroundColor:
                              index == i ? Colors.blue : Colors.white,
                        )),
                    onTap: () {
                      setState(() {
                        startX = endX = 0;
                        index = i;
                      });
                    },
                  ),
                ).toList(),
              ),
            )
          ],
        ),
        alignment: Alignment.center,
      ),
    );
  }

  void _getIndex(int delta) {
    if (delta > 50) {
      setState(() {
        index--;
        index = index.clamp(0, widget.picList.length - 1);
      });
    } else if (delta < 50) {
      setState(() {
        index++;
        index = index.clamp(0, widget.picList.length - 1);
      });
    }
  }
}

class FadeRoute extends PageRouteBuilder {
  final Widget page;
  FadeRoute({this.page})
      : super(
          pageBuilder: (
            BuildContext context,
            Animation<double> animation,
            Animation<double> secondaryAnimation,
          ) =>
              page,
          transitionsBuilder: (
            BuildContext context,
            Animation<double> animation,
            Animation<double> secondaryAnimation,
            Widget child,
          ) =>
              FadeTransition(
            opacity: animation,
            child: child,
          ),
        );
}
